#!/usr/bin/env python
# -*- coding: utf-8 -*-

import MySQLdb
import time

db = MySQLdb.connect("127.0.0.1", "root", "123456", "python", charset='utf8')

cursor = db.cursor()

# cursor.execute("DROP TABLE IF EXISTS admin")
#
# sql = """CREATE TABLE admin (
#          FIRST_NAME  CHAR(20) NOT NULL,
#          LAST_NAME  CHAR(20),
#          AGE INT,
#          SEX CHAR(1),
#          INCOME FLOAT )"""
# cursor.execute(sql)

# sql = """INSERT INTO admin(FIRST_NAME,
#          LAST_NAME, AGE, SEX, INCOME)
#          VALUES ('Mac', 'Mohan', 20, 'M', 2000)"""
newTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
username = 'pengjian'
password = 123456
sex = 1
email = 'szpengjian@gamil.com'
addtime = newTime
updatetime = newTime

# sql = """INSERT INTO member(username, password, sex, email, addtime, updatetime) VALUES ()"""


sql = "INSERT INTO member(username, password, sex, email, addtime, updatetime) \
       VALUES ('%s', '%d', '%d', '%s', '%s', '%s' )" % \
       (username, password, sex, email, addtime, updatetime)
try:
    cursor.execute(sql)
    db.commit()
except:
    db.rollback()

db.close()




